package com.sunnypower.rushfitapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

public class RateCourseActivity extends Activity {
    private TextView rate_course_name;
    private RadioGroup rate_radio_group;
    private Button rate_btn;
    private String rate = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_rate_courese);
        rate_course_name = findViewById(R.id.rate_course_name);
        rate_radio_group = findViewById(R.id.rate_radio_group);
        rate_btn = findViewById(R.id.rate_btn);
        rate_btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if ("".equals(rate)) {
                    Toast.makeText(getApplicationContext(), "请选择您的评分！", Toast.LENGTH_SHORT).show();
                } else {
                    Intent intent = new Intent();
                    intent.putExtra("rate", rate);
                    setResult(RESULT_OK, intent);
                    finish();
                }
            }
        });
        rate_course_name.setText(getIntent().getStringExtra("courseName"));
        rate_radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                switch (checkedId) {
                    case R.id.rate_1:
                        rate = "1";
                        break;
                    case R.id.rate_2:
                        rate = "2";
                        break;
                    case R.id.rate_3:
                        rate = "3";
                        break;
                    case R.id.rate_4:
                        rate = "4";
                        break;
                    case R.id.rate_5:
                        rate = "5";
                        break;
                }
            }
        });
    }
}
